//package com.ruoyi.framework.config;
//
//import com.ruoyi.common.utils.security.RsaUtils;
//import org.springframework.context.EnvironmentAware;
//import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
//import org.springframework.core.env.ConfigurableEnvironment;
//import org.springframework.core.env.Environment;
//import org.springframework.core.env.MapPropertySource;
//import org.springframework.core.env.MutablePropertySources;
//import org.springframework.stereotype.Component;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @Author alison
// * @Date 2024/12/25 13:39
// * @Version 1.0
// * @Description
// */
//@Component
//public class EncryptPropertySourcesPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer implements EnvironmentAware {
//    @Override
//    public void setEnvironment(Environment environment) {
//        if (environment instanceof ConfigurableEnvironment) {
//            ConfigurableEnvironment environment1 = (ConfigurableEnvironment) environment;
//            String key = "spring.datasource.druid.master.password";
//            String publickey_word = "spring.datasource.druid.publicKey";
//            String pwd_prefix = "jasypt.encryptor.property.prefix";
//            String pwd_suffix = "jasypt.encryptor.property.suffix";
//
//            String pwd = environment1.getProperty(key);
//            String publickey = environment1.getProperty(publickey_word);
//            String pwd_prefix_val = environment1.getProperty(pwd_prefix);
//            String pwd_suffix_val = environment1.getProperty(pwd_suffix);
//            pwd = pwd.replace(pwd_prefix_val, "").replace(pwd_suffix_val, "");
//            try {
//                pwd = RsaUtils.decryptByPublicKey(publickey, pwd);
//            } catch (Exception e) {
//            }
//            MutablePropertySources propertySources1 = environment1.getPropertySources();
//            Map source = new HashMap<>();
//            source.put(key, pwd);
//            MapPropertySource mapPropertySource = new MapPropertySource("embeddedProp", source);
//            propertySources1.addLast(mapPropertySource);
//        }
//    }
//
////    @Override
////    protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, ConfigurablePropertyResolver propertyResolver) throws BeansException {
////        super.processProperties(beanFactoryToProcess, propertyResolver);
////    }
//}
